package com.flyduck.vueshop.cart.remote.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyduck.vueshop.cart.entity.AppCartItem;
import com.flyduck.vueshop.cart.mapper.AppCartItemMapper;
import com.flyduck.vueshop.cart.remote.service.RemoteCartItemService;
import com.flyduck.vueshop.cart.vo.RemoteCartItemRespVO;
import com.flyduck.vueshop.common.core.utils.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * RemoteCartItemServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2024-07-23
 */
@Service
public class RemoteCartItemServiceImpl implements RemoteCartItemService {

    @Resource
    private AppCartItemMapper appCartItemMapper;

    @Override
    public List<RemoteCartItemRespVO> getCartItemListByIds(List<Long> ids) {
        List<AppCartItem> appCartItemList = appCartItemMapper.selectList(
                new LambdaQueryWrapper<AppCartItem>()
                        .in(AppCartItem::getId, ids)
                        .orderByDesc(AppCartItem::getCreated)
        );
        return BeanUtils.toBeanList(appCartItemList,RemoteCartItemRespVO.class);
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        appCartItemMapper.deleteBatchIds(ids);
    }
}
